﻿using BP.Plugin.Monitor.Application.Common.Interfaces;
using BP.Plugin.Monitor.Infrastructure;
using BP.Plugin.Monitor.Infrastructure.Middlewares;
using BP.Plugin.Monitor.Infrastructure.Persistence;
using Core.Infrastructure;
using Core.Persistence;
using Infrastructure.Mvc.Routing;
using Infrastructure.Persistence;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace BP.Plugin.Monitor;

/// <summary>
/// 系统监控
/// </summary>
public class BoilerplateStartup : IBoilerplateStartup
{
    public int Order => 3000;

    public void Configure(IApplicationBuilder application)
    {
        
    }

    public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
    {
        #region 数据库上下文
        ArgumentNullException.ThrowIfNull(services);
        services.BindDbContext<MonitorDbContext>();

        services.AddScoped<IMonitorDbContext>(
            provider => provider.GetRequiredService<MonitorDbContext>());
        #endregion

        services.AddHostedService<OnlineUserMonitorBackgroundService>();
        services.AddHostedService<TenantLogSyncService>();
    }
}

